package org.hot100_2;

import java.util.Stack;

public class leetcode739 {
    public int[] dailyTemperatures(int[] temperatures) {

        int n = temperatures.length;
        Stack<Integer> stack = new Stack<>();
        int [] res = new int[n];

        for (int i = 0; i < n; i++) {

            while (!stack.isEmpty() && temperatures[i]>temperatures[stack.peek()]){
                Integer changeIndex = stack.pop();
                res[changeIndex]=i-changeIndex;
            }

            stack.push(i);
        }

        return res;
    }
}
